-#![crate_id="cargo-clean"]
+#![crate_name="cargo-clean"]
#![feature(phase)]
extern crate cargo;
};
use util::{CargoResult, CargoError};
-use core::source::Location;
+use core::source::SourceId;
trait ToVersion {
fn to_version(self) -> Result<semver::Version, String>;
pub struct PackageId {
name: String,
version: semver::Version,
- namespace: Location,
+ source_id: SourceId,
}
#[deriving(Clone, Show, PartialEq)]
impl PackageId {
pub fn new<T: ToVersion>(name: &str, version: T,
- ns: &Location) -> CargoResult<PackageId> {
+ sid: &SourceId) -> CargoResult<PackageId> {
let v = try!(version.to_version().map_err(InvalidVersion));
Ok(PackageId {
name: name.to_str(),
version: v,
- namespace: ns.clone()
+ source_id: sid.clone()
})
}
&self.version
}
- pub fn get_namespace<'a>(&'a self) -> &'a Location {
- &self.namespace
+ pub fn get_source_id<'a>(&'a self) -> &'a SourceId {
+ &self.source_id
}
}
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
try!(write!(f, "{} v{}", self.name, self.version));
- if self.namespace.to_str().as_slice() != central_repo {
- try!(write!(f, " ({})", self.namespace));
+ if self.source_id.to_str().as_slice() != central_repo {
+ try!(write!(f, " ({})", self.source_id));
}
Ok(())
Decodable<D,Box<CargoError + Send>>
for PackageId
{
- fn decode(d: &mut D) -> Result<PackageId, Box<CargoError + Send>> {
- let vector: Vec<String> = try!(Decodable::decode(d));
+ fn decode(d: &mut D) -> CargoResult<PackageId> {
+ let (name, version, source_id): (String, String, SourceId) = try!(Decodable::decode(d));
- PackageId::new(
- vector.get(0).as_slice(),
- vector.get(1).as_slice(),
- &try!(Location::parse(vector.get(2).as_slice())))
+ PackageId::new(name.as_slice(), version.as_slice(), &source_id)
}
}
impl<E, S: Encoder<E>> Encodable<S,E> for PackageId {
fn encode(&self, e: &mut S) -> Result<(), E> {
- (vec!(self.name.clone(), self.version.to_str()),
- self.namespace.to_str()).encode(e)
+ (self.name.clone(), self.version.to_str(), self.source_id.clone()).encode(e)
}
}
#[cfg(test)]
mod tests {
use super::{PackageId, central_repo};
- use core::source::Location;
+ use core::source::{Location, RegistryKind, SourceId};
#[test]
fn invalid_version_handled_nicely() {
- let repo = Location::parse(central_repo).unwrap();
+ let loc = Location::parse(central_repo).unwrap();
+ let repo = SourceId::new(RegistryKind, loc);
+
assert!(PackageId::new("foo", "1.0", &repo).is_err());
assert!(PackageId::new("foo", "1", &repo).is_err());
assert!(PackageId::new("foo", "bar", &repo).is_err());
Dependency,
PackageId,
Summary,
- Registry
+ Registry,
};
use util::{CargoResult, human, internal};
)
)
- fn registry_loc() -> Location {
- Location::parse("http://www.example.com/").unwrap()
+ fn registry_loc() -> SourceId {
+ let remote = Location::parse("http://www.example.com/").unwrap();
+ SourceId::new(RegistryKind, remote)
}
fn pkg(name: &str) -> Summary {
use std::fmt;
use std::fmt::{Show, Formatter};
+use serialize::{Decodable, Decoder, Encodable, Encoder};
use url::Url;
use core::{Summary, Package, PackageId};
use sources::{PathSource, GitSource};
use sources::git;
-use util::{Config, CargoResult};
+use util::{Config, CargoResult, CargoError};
use util::errors::human;
/// A Source finds and downloads remote packages based on names and
fn fingerprint(&self, pkg: &Package) -> CargoResult<String>;
}
-#[deriving(Show, Clone, PartialEq, Eq, PartialOrd, Ord)]
+#[deriving(Encodable, Decodable, Show, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum SourceKind {
/// GitKind(<git reference>) represents a git repository
GitKind(String),
Remote(Url),
}
-#[deriving(Clone, Eq)]
+type Error = Box<CargoError + Send>;
+
+impl<E, D: Decoder<E>> Decodable<D, E> for Location {
+ fn decode(d: &mut D) -> Result<Location, E> {
+ let url: String = raw_try!(Decodable::decode(d));
+ Ok(Location::parse(url.as_slice()).unwrap())
+ }
+}
+
+impl<E, S: Encoder<E>> Encodable<S, E> for Location {
+ fn encode(&self, e: &mut S) -> Result<(), E> {
+ self.to_str().encode(e)
+ }
+}
+
+#[deriving(Encodable, Decodable, Clone, Eq)]
pub struct SourceId {
pub kind: SourceKind,
pub location: Location,
SourceId { kind: GitKind(ref reference), ref location } => {
try!(write!(f, "{}", location));
if reference.as_slice() != "master" {
- try!(write!(f, " (ref={})", reference));
+ try!(write!(f, "#ref={}", reference));
}
},
SourceId { kind: RegistryKind, .. } => {
bins.push(root.join("src/main.rs"));
}
- fs::readdir(&root.join("src/bin"))
+ let _ = fs::readdir(&root.join("src/bin"))
.map(|v| v.move_iter())
.map(|i| i.filter(|f| f.extension_str() == Some("rs")))
.map(|mut i| i.collect())
}
impl TomlProject {
- pub fn to_package_id(&self, namespace: &Location) -> CargoResult<PackageId> {
- PackageId::new(self.name.as_slice(), self.version.as_slice(), namespace)
+ pub fn to_package_id(&self, source_id: &SourceId) -> CargoResult<PackageId> {
+ PackageId::new(self.name.as_slice(), self.version.as_slice(), source_id)
}
}
try!(process_dependencies(&mut cx, true, self.dev_dependencies.as_ref()));
}
- let pkgid = try!(project.to_package_id(source_id.get_location()));
+ let pkgid = try!(project.to_package_id(source_id));
let summary = Summary::new(&pkgid, deps.as_slice());
Ok((Manifest::new(
&summary,
assert_that(project.cargo_process("cargo-build"),
execs()
.with_stdout(format!("{} git repository `file:{}`\n\
- {} dep1 v0.5.0 (file:{})\n\
+ {} dep1 v0.5.0 (file:{}#ref=branchy)\n\
{} foo v0.5.0 (file:{})\n",
UPDATING, git_root.display(),
COMPILING, git_root.display(),
assert_that(project.cargo_process("cargo-build"),
execs()
.with_stdout(format!("{} git repository `file:{}`\n\
- {} dep1 v0.5.0 (file:{})\n\
+ {} dep1 v0.5.0 (file:{}#ref=v0.1.0)\n\
{} foo v0.5.0 (file:{})\n",
UPDATING, git_root.display(),
COMPILING, git_root.display(),